﻿//import log
var box = {};
box.count = 0;

//打开一个远程地址的内容
box.open_url = function (title, url, attrs, is_modal, width, height) {
    $.post(url, attrs, function (html) {
        box.open(title, html, is_modal, width, height);
    });
}

box.dialog_tree = function (title, content, attrs) {
    var box_id = box.create_box(title, content);
    $("#" + box_id).wijdialog({
        modal: true,
        open: function (e) {
//            $('#container_id').fileTree({
//                root: '',
//                script: 'jqueryFileTree/connectors/jqueryFileTree.aspx',
//                expandSpeed: 1000,
//                collapseSpeed: 1000,
//                multiFolder: false,
//                baseUrl: $("#baseUrl").val()
//            }, function (file) {
//                alert(file);
//            });
        }
    });
    $("#" + box_id).wijdialog(attrs);
    //$("#" + box_id).wijdialog(attrs);
    $("#" + box_id).wijdialog("open");


    $('.container_id').fileTree1({
        root: '',
        script: 'jqueryFileTree/connectors/jqueryFileTree.aspx',
        expandSpeed: 1000,
        collapseSpeed: 1000,
        multiFolder: false,
        baseUrl: $("#baseUrl").val()
    }, function (file) {
        alert(file);
    });
}

box.dialog = function (title, content, attrs) {
    var box_id = box.create_box(title, content);
    $("#" + box_id).wijdialog(attrs);
    return box_id;
}

box.open_window = function (title, url, width, height) {
    var box_id = box.create_box(title, "");
    $("#" + box_id).wijdialog({ width: width, height: height, contentUrl: url, autoOpen: true ,modal: true});
}

box.create_box = function (title, content) {
    box.count++;
    var box_id = "dialog_" + box.count;
    var html = "<div id='" + box_id + "' title='" + title + "'>";
    html += content;
    html += "</div>";
    $("body").append(html);
    return box_id;
}

box.open = function (title, content, is_modal, width, height) {
    width = width == null ? 500 : width;
    height = height == null ? 300 : height;
    var box_id = box.create_box(title, content);
    $("#" + box_id).wijdialog({
        autoOpen: true,
        modal: is_modal,
        width: width,
        height: height
    });
}

box.alert = function (title, content, action) {

    var box_id = box.create_box(title, content);
    $("#" + box_id).wijdialog({
        autoOpen: true,
        modal: true,
        buttons: [{ text: lang.I_Kown, click: function () {
            $(action);
              $(this).wijdialog("close");}}]
//         {
//            iknnn: function () {
//                $(action);
//                $(this).wijdialog("close");
//            }
//        }
        ,
        captionButtons: {
            pin: { visible: false },
            refresh: { visible: false },
            toggle: { visible: false },
            minimize: { visible: false },
            maximize: { visible: false }
        }
    });
    log.log_text(title + "：" + content, true);
}

box.error = function (content, action) {
    var iknnn = lang.I_Kown;
    alert(lang.I_Kown);
    var box_id = box.create_box(lang.Error, content);
    $("#" + box_id).wijdialog({
        autoOpen: true,
        modal: true,
         buttons: [{ text: lang.I_Kown, click: function () {
            $(action);
              $(this).wijdialog("close");}}]
//            iknnn: function () {
//                $(action);
//                $(this).wijdialog("close");
//            }
        ,
        captionButtons: {
            pin: { visible: false },
            refresh: { visible: false },
            toggle: { visible: false },
            minimize: { visible: false },
            maximize: { visible: false }
        }
    });
    log.log_text(lang.Error + "：" + content, false);
}

box.confirm = function (title, content, action) {
    var box_id = box.create_box(title, content);
    $("#" + box_id).wijdialog({
        autoOpen: true,
        modal: true,
        buttons: [
            { 
                text: lang.I_Kown, click: function () {
                    $(action);
                    $(this).wijdialog("close");}
            }
        ],
        buttons: 
        {
            text:  lang.Yes, click: function () {
                    $(action);
                    $(this).wijdialog("close");},
            text:  lang.No, click: function () {
                    $(action);
                    $(this).wijdialog("close");},
            text:  lang.Cancel, click: function () {
                    $(action);
                    $(this).wijdialog("close");}
//            lang.Yes: function () {
//                $(action);
//                $(this).wijdialog("close");
//            },
//           lang.No: function () {
//                $(this).wijdialog("close");
//            },
//           lang.Cancel: function () {
//                $(this).wijdialog("close");
//            }
        },
        captionButtons: {
            pin: { visible: false },
            refresh: { visible: false },
            toggle: { visible: false },
            minimize: { visible: false },
            maximize: { visible: false }
        }
    });
}

box.prompt = function (title, content, action) {
    var box_id = box.create_box(title, content + "<br/><input type='text' class='hu8-prompt-question' />");
    $("#" + box_id).wijdialog({
        autoOpen: true,
        height: 180,
        width: 400,
        modal: true,
        buttons: {
            Ok: function () {
                var value = $(action);
                $(this).wijdialog("close");
            }
        },
        captionButtons: {
            pin: { visible: false },
            refresh: { visible: false },
            toggle: { visible: false },
            minimize: { visible: false },
            maximize: { visible: false }
        }
    });
}